//
//  GetProductDetailViewController.m
//  HAODE
//
//  Created by panquanReabam.com on 15/9/19.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//

#import "ProductGetMaterialDetailViewController.h"


#import "HttpRequest.h"
#import "JSONKit.h"
#import "ProductView.h"
#import "HAODEsingleton.h"
#import "UIButton+WebCache.h"
#import "shouyinCell.h"
#import "RDVTabBarController.h"
#import "ShopcatListViewController.h"
#import "TheLoginViewController.h"
#import "VPImageCropperViewController.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import "UpYun.h"
#import "productdetailsView.h"
#import "editorProductViewController.h"
#import "UMSocial.h"
#import "QRCodeGenerator.h"
#import "EditProductSaveMaterialViewController.h"
#define ORIGINAL_MAX_WIDTH 420.0f
@interface ProductGetMaterialDetailViewController ()<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate,UIWebViewDelegate, UITextViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIAlertViewDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UIActionSheetDelegate,UMSocialUIDelegate>
@property (nonatomic, strong) UIImageView *portraitImageView;
@property (nonatomic,strong) UIImagePickerController *ipc;
@property (strong, nonatomic) UIImage *sendImage;
@property(nonatomic,retain)NSMutableArray* xuanxiang;
@property (retain, nonatomic) NSDictionary* dictionary;
@property(nonatomic,strong)   NSString*shareUrl;
@property (weak, nonatomic) UIPageControl * pageControl;
@property (nonatomic,retain)UIImageView* image1;
@property(nonatomic,strong)   NSString*shuoming;

@end

@implementation ProductGetMaterialDetailViewController
{
    BOOL saveAccount;
    int requestState;
    int goodsPrice;
    UIImage *image;
    HAODEsingleton* commdity;
    UIWebView *webview;
    UIScrollView *myscrollView;
    UIScrollView *scrollView;
    UILabel *textlabel2;
    ProductView*clothView;
    UITableView *table_list;
    UIButton*idname1;
    NSMutableArray*images;
    NSMutableArray*specList;
    NSMutableArray*arr;
    UIView*backview1;
    UIButton*bbuyBtn;
    UIButton*orderBtn1;
    UIButton* backButton1;
    UIButton*buttonimage;
    UIView*view11;
    UIView *guigeview;
    UIView*diview;
    NSDictionary*dataDicts;
    UIButton*tureBtn;
    UIImageView *imageview;
    UILabel* shu;
    NSString*specId;
    UIImageView*chaimageview;
    NSMutableArray*arrays;
    NSMutableArray*imagearrays;
    NSMutableArray*imageUrlarrays;
    UIView*statusBarView;
    UIView*fengxiangview;
    UIButton* quxiao;
    UIScrollView*fengxiangScroll;
    NSMutableArray*guigetitle ;
    NSMutableArray*specIdarr ;
    NSMutableArray*price ;
    NSString*itemCode;
    NSMutableArray*specInvarr ;
    UIButton*erweima;
    UIButton*erweima1;
}


@synthesize alt = alt;

-(void)BackAction:(UIButton *)sender{
    
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [[UIApplication sharedApplication] setStatusBarHidden:TRUE];
    [[self rdv_tabBarController] setTabBarHidden:YES];
    
       UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.font=[UIFont systemFontOfSize:13];
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    self.navigationController.navigationBarHidden=NO;
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    
    
    
    
    
    
    if ([commdity.gengxinxiangqing isEqualToString:@""]) {
        [myscrollView removeFromSuperview];
        [self add];
    }else{
        
        
        
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
}



-(void)editor:(UIButton*)sender{
    commdity.gengxinxiangqing=@"123";
    EditProductSaveMaterialViewController *detailViewController = [[EditProductSaveMaterialViewController alloc] init];
    [self.navigationController pushViewController:detailViewController animated:YES];
    
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    _table.delegate=self;
    _table.dataSource=self;
   
    
    _table.separatorStyle=UITableViewCellSeparatorStyleNone;
    commdity=[HAODEsingleton shared];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor blackColor],
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    
    
    
    
    
    
    UIButton*editor = [[UIButton alloc] initWithFrame:CGRectMake(0, 0.0, 26, 26)];
    [editor setImage:[UIImage imageNamed:@"fenxiang"] forState:UIControlStateNormal];
    [editor addTarget:self action:@selector(fenxiangss:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton*editor1 = [[UIButton alloc] initWithFrame:CGRectMake(30, 0.0, 30, 30)];
    [editor1 setImage:[UIImage imageNamed:@"bianji"] forState:UIControlStateNormal];
    [editor1 addTarget:self action:@selector(editor:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem* myBtnBtn = [[UIBarButtonItem alloc] initWithCustomView:editor];
    UIBarButtonItem* myBtnBtn1 = [[UIBarButtonItem alloc] initWithCustomView:editor1];
    
    NSArray *buttonArray = [[NSArray alloc]initWithObjects:myBtnBtn1,myBtnBtn, nil];
    self.navigationItem.rightBarButtonItems = buttonArray;
    
    
    
    
}









-(void)closeKeyBoad
{
    [fengxiangview removeFromSuperview];
    [fengxiangScroll removeFromSuperview];
    [quxiao removeFromSuperview];
    [tureBtn removeFromSuperview];
    [diview removeFromSuperview];
    [scrollView removeFromSuperview];
    [chaimageview removeFromSuperview];
    
    [erweima removeFromSuperview];
    [erweima1 removeFromSuperview];
}
-(void)fenxiangss:(UIButton*)sender{
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:@"product" forKey:@"contentType"];
    [param setValue:commdity.itemId forKey:@"contentId"];
    [param setValue:@"wx_single" forKey:@"shareTarget"];
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    
    
    [HttpRequest requestData:@"Company/getShareUrl" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                self.shuoming=[severDataDict.dataDict objectForKey:@"shareDescription"];
                self.shareUrl=[severDataDict.dataDict objectForKey:@"shareUrl"];
                
                fengxiangview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
                fengxiangview.backgroundColor=[UIColor blackColor];
                fengxiangview.alpha=0.5;
                [self.view addSubview:fengxiangview];
                
                fengxiangScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,ScreenHeight-240, ScreenWidth,200)];
                fengxiangScroll.delegate = self;
                fengxiangScroll.userInteractionEnabled = YES;
                fengxiangScroll.scrollEnabled = YES;
                fengxiangScroll.showsVerticalScrollIndicator = FALSE;
                fengxiangScroll.showsHorizontalScrollIndicator = FALSE;
                fengxiangScroll.backgroundColor=[UIColor whiteColor];
                [self .view addSubview:fengxiangScroll];
                
                // 手势
                UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
                singleFingerOne.numberOfTouchesRequired = 1; //手指数
                singleFingerOne.numberOfTapsRequired = 1; //tap次数
                singleFingerOne.delegate = self;
                [fengxiangview addGestureRecognizer:singleFingerOne];
                
                
                
                
                NSArray*nameBtn=[[NSArray alloc]initWithObjects:@"发送給朋友",@"分享到朋友圈",nil];
                NSArray *arrayimage = @[@"faweixin",@"fenxiangpenyouquan"];
                for (int i = 0; i<2; i++) {
                    UIButton *nameButcenter = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/3*i,   80*ScreenHeight/1334+15, ScreenWidth/3, 60)];
                    
                    [fengxiangScroll addSubview:nameButcenter];
                    
                    
                    UIButton *nameBut = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/3*i,   nameButcenter.bottom+20, ScreenWidth/3, 14)];
                    [nameBut setTitle: [nameBtn objectAtIndex:i]  forState:UIControlStateNormal];
                    nameBut.tag=201+i;
                    [nameBut setTitleColor:shenhuicolor forState:0];
                    nameBut.titleLabel.font=[UIFont systemFontOfSize:14];
                    [nameBut addTarget:self action:@selector(fengxiang:) forControlEvents:UIControlEventTouchUpInside];
                    [fengxiangScroll addSubview:nameBut];
                    
                    
                    UIButton *wuyebuttonimage = [UIButton buttonWithType:UIButtonTypeCustom];
                    wuyebuttonimage.frame = CGRectMake(ScreenWidth/3*i,  10, 60, 60);
                    
                    wuyebuttonimage.tag = 201+i;
                    wuyebuttonimage.center=nameButcenter.center;
                    [wuyebuttonimage setImage:[UIImage imageNamed: [arrayimage objectAtIndex:i]] forState:UIControlStateNormal];
                    [wuyebuttonimage addTarget:self action:@selector(fengxiang:) forControlEvents:UIControlEventTouchUpInside];
                    [fengxiangScroll addSubview:wuyebuttonimage];
                    
                    
                }
                
                
                quxiao = [[UIButton alloc] initWithFrame:CGRectMake(0,ScreenHeight-45,  ScreenWidth, 45)];
                [quxiao setTitle:@"取消" forState:UIControlStateNormal];
                quxiao.titleLabel.font=[UIFont systemFontOfSize:16];
                quxiao.backgroundColor=[UIColor whiteColor];
                [quxiao setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                [quxiao addTarget:self action:@selector(closeKeyBoad) forControlEvents:UIControlEventTouchUpInside];
                [self .view addSubview:quxiao];
                UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, ScreenWidth-30, 0.35)];
                line.backgroundColor=qianhuicolor;
                [quxiao addSubview:line];
                
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
    
    
}






-(void)fengxiang:(UIButton*)sender{
    [fengxiangview removeFromSuperview];
    [fengxiangScroll removeFromSuperview];
    [quxiao removeFromSuperview];
    NSURL *url = [NSURL URLWithString:[[[dataDicts valueForKey:@"imageList"] objectAtIndex:0]objectForKey:@"imageUrlFull"]];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *image1 = [[UIImage alloc] initWithData:data];
    if (sender.tag==201) {
        if (![[commdity.Dict objectForKey:@"details"]isEqualToString:@""]) {
            self.shuoming=[commdity.Dict objectForKey:@"details"];
        }
        [UMSocialData defaultData].extConfig.wechatSessionData.title =[commdity.Dict objectForKey:@"itemName"];
        UMSocialUrlResource *urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeDefault url:self.shareUrl];
        
        [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatSession].snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
        [UMSocialData defaultData].extConfig.wechatSessionData.url = self.shareUrl;
        [[UMSocialDataService defaultDataService]postSNSWithTypes:@[UMShareToWechatSession] content:self.shuoming image:image1 location:nil urlResource:urlResource presentedController:self completion:^(UMSocialResponseEntity *response){
            
            if (response.responseCode == UMSResponseCodeSuccess) {
                NSLog(@"分享成功！");
            }
            
        }];
        
        
        
        
        
        
    }
    
    if (sender.tag==202) {
        
        //       [UMSocialData defaultData].extConfig.wechatSessionData.title =[commdity.Dict objectForKey:@"itemName"];
        UMSocialUrlResource *urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeDefault url:self.shareUrl];
        [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatTimeline].snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
        [UMSocialData defaultData].extConfig.wechatTimelineData.url = self.shareUrl;
        [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatTimeline] content:[NSString stringWithFormat:@"%@",  [commdity.Dict objectForKey:@"itemName"]] image:image1 location:nil urlResource:urlResource presentedController:self completion:^(UMSocialResponseEntity *response){
            if (response.responseCode == UMSResponseCodeSuccess) {
                NSLog(@"分享成功！");
            }
        }];
        
        
        
        
    }
    
}



//- (void)setDataUrl:(NSString *)url shareImage:(UIImage *)img
//{
//    [UMSocialData defaultData].extConfig.qzoneData.shareImage = img;
//
//    [UMSocialData defaultData].extConfig.qqData.url = url;
//    [UMSocialData defaultData].extConfig.qzoneData.url = url;
//    [UMSocialData defaultData].extConfig.wechatSessionData.url = url;
//    [UMSocialData defaultData].extConfig.wechatTimelineData.url = url;
//    [UMSocialData defaultData].extConfig.yxtimelineData.url = url;
//    [UMSocialData defaultData].extConfig.yxsessionData.url = url;
//
//}
//
-(void )add{
    
    arr=[[NSMutableArray alloc]init];
    imagearrays=[[NSMutableArray alloc]init];
    images=[[NSMutableArray alloc]init];
    arrays=[[NSMutableArray alloc]init];
    imageUrlarrays=[[NSMutableArray alloc]init];
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    
    [param setValue:commdity.itemId forKey:@"itemId"];
    
    NSLog(@"====%@",param);
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    
    
    [HttpRequest requestData:@"Product/GetMaterialDetail" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            NSLog(@"====%@",severDataDict.dataDict);
            
            
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                dataDicts=severDataDict.dataDict;
                
                commdity.Dict=severDataDict.dataDict;
                commdity.content=[severDataDict.dataDict objectForKey:@"itemType"];
                commdity.code=[severDataDict.dataDict objectForKey:@"itemTypeCode"];
                commdity.DataLine=[severDataDict.dataDict objectForKey:@"tagList"];
                commdity.code=[severDataDict.dataDict objectForKey:@"itemTypeCode"];
                
                commdity.userName=[severDataDict.dataDict objectForKey:@"supplier"];
                commdity.supplierId=[severDataDict.dataDict valueForKey:@"supplierId"];
               
                commdity.specListarr=[severDataDict.dataDict objectForKey:@"specList"];
                
                specList=[severDataDict.dataDict objectForKey:@"specList"];
                arrr=[severDataDict.dataDict objectForKey:@"tagList"];
            
                
                NSMutableArray* Codearrr=[[NSMutableArray alloc]init];
                NSMutableArray* Namearrr=[[NSMutableArray alloc]init];
                for (NSDictionary* dicc in arrr )
                {
                    [Codearrr addObject:[dicc valueForKey:@"code"]];
                    [Namearrr addObject:[dicc valueForKey:@"content"]];
                    
                    
                }
                
                commdity.selectTagNameArray=[Namearrr copy];
                commdity.selectTagCodeArray=[Codearrr copy];

                
                myscrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, ScreenHeight)];
                myscrollView.delegate = self;
                myscrollView.userInteractionEnabled = YES;
                myscrollView.scrollEnabled = YES;
                myscrollView.showsVerticalScrollIndicator = FALSE;
                myscrollView.showsHorizontalScrollIndicator = FALSE;
                [self.view addSubview:myscrollView];
                
                if (![severDataDict.dataDict isEqual:[NSNull null]]) {
                    itemCode=[severDataDict.dataDict valueForKey:@"itemCode"];
                    productdetailsView *view1 = [[productdetailsView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 450)];
                    [view1.erweimaImageview addTarget:self action:@selector(erweimaImageview:) forControlEvents:UIControlEventTouchUpInside];
                    view1.itemName.text=[NSString stringWithFormat:@"%@",[severDataDict.dataDict valueForKey:@"itemName"]];
                    view1.itemCode.text=[NSString stringWithFormat:@"No %@",[severDataDict.dataDict valueForKey:@"itemCode"]];
                    view1.saleQty.text=[NSString stringWithFormat:@"库存 %@",[severDataDict.dataDict valueForKey:@"invQty"]];NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"库存 %@  件",  [dataDicts valueForKey:@"invQty"]]];
                    
                    [AttributedStr addAttribute:NSFontAttributeName
                     
                                          value:[UIFont systemFontOfSize:15.0]
                     
                                          range:NSMakeRange(2, 4)];
                    
                    [AttributedStr addAttribute:NSForegroundColorAttributeName
                     
                                          value: [UIColor blackColor]
                     
                                          range:NSMakeRange(2, 4)];
                    
                    
                    view1.saleQty.attributedText = AttributedStr;
                    
                    
                    if (![severDataDict.dataDict isEqual:[NSNull null]]) {
                        NSMutableArray *array = [NSMutableArray arrayWithCapacity:[[severDataDict.dataDict valueForKey:@"imageList"] count]];
                        
                        for (NSDictionary *dic in [severDataDict.dataDict valueForKey:@"imageList"]) {
                            [array addObject:[dic objectForKey:@"imageUrlFull"]];
                            [self getImageFromURL:[dic objectForKey:@"imageUrlFull"]];
                            [self getImageFromURLs:[dic objectForKey:@"imageUrl"]];
                        }
                        
                        view1.arrayImage = array;
                        
                    }else {
                        view1.arrayImage = @[@"http://miandan.b0.upaiyun.com/Product/9aafbbd4-febc-46dc-9197-4f92e87737f1.png"];
                        
                    }
                    
                    
                    
                    
                    [myscrollView addSubview:view1];
                    
                    
                    
                    NSInteger number ;
                    number=[[severDataDict.dataDict objectForKey:@"specList"]count];
                    
                    if (number>0) {
                        
                        
                        if ([[NSString stringWithFormat:@"%@",[severDataDict.dataDict objectForKey:@"minPrice"] ]isEqualToString:[NSString stringWithFormat:@"%@",[severDataDict.dataDict objectForKey:@"maxPrice"]]]) {
                                                       NSString*GoldPrice1=[NSString stringWithFormat:@"%@",  [severDataDict.dataDict objectForKey:@"maxPrice"]];
                            NSNumberFormatter *numberFormatter1 = [[NSNumberFormatter alloc] init];
                            [numberFormatter1 setPositiveFormat:@"###,##0;"];
                            NSString *formattedNumberString1 = [numberFormatter1 stringFromNumber:[NSNumber numberWithDouble:GoldPrice1.floatValue]];
                            
                            
                            UILabel*specPrice=[[UILabel alloc]initWithFrame:CGRectMake(20, view1.bottom-5, 200, 45)];
                            specPrice.text=[NSString stringWithFormat:@"¥ %@",formattedNumberString1];
                            specPrice.font=[UIFont systemFontOfSize:18];
                            specPrice.textColor=hongsecolor;
                            
                            [myscrollView addSubview:specPrice];
                        }else{
                        NSString*GoldPrice=[NSString stringWithFormat:@"%@",  [severDataDict.dataDict objectForKey:@"minPrice"]];
                        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                        [numberFormatter setPositiveFormat:@"###,##0;"];
                        NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
                        
                        NSString*GoldPrice1=[NSString stringWithFormat:@"%@",  [severDataDict.dataDict objectForKey:@"maxPrice"]];
                        NSNumberFormatter *numberFormatter1 = [[NSNumberFormatter alloc] init];
                        [numberFormatter1 setPositiveFormat:@"###,##0;"];
                        NSString *formattedNumberString1 = [numberFormatter1 stringFromNumber:[NSNumber numberWithDouble:GoldPrice1.floatValue]];
                        
                        
                        UILabel*specPrice=[[UILabel alloc]initWithFrame:CGRectMake(20, view1.bottom-5, 200, 45)];
                        specPrice.text=[NSString stringWithFormat:@"¥ %@~%@",formattedNumberString,formattedNumberString1];
                        specPrice.font=[UIFont systemFontOfSize:18];
                        specPrice.textColor=hongsecolor;
                        
                            [myscrollView addSubview:specPrice];}
                        UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(15,view1.bottom+45-0.35, ScreenWidth-30, 0.5)];
                        _xianview.image=[UIImage imageNamed:@"hengxian"];
                        [myscrollView addSubview:_xianview];

                        for (int i = 0; i < number; i++) {
                            
                            guigeview = [[UIView alloc]initWithFrame:CGRectMake(0, _xianview.bottom+45*i, ScreenWidth, 45)];
                            
                            guigeview.backgroundColor=[UIColor whiteColor];
                            NSString*GoldPrice=[NSString stringWithFormat:@"%@",  [[[severDataDict.dataDict objectForKey:@"specList"]objectAtIndex:i]objectForKey:@"specPrice"]];
                            NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                            [numberFormatter setPositiveFormat:@"###,##0.00;"];
                            NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
                            UILabel*specName=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, ScreenWidth, 45)];
                            specName.text=[NSString stringWithFormat:@"%@  库存 %@ ¥ %@",[[[severDataDict.dataDict objectForKey:@"specList"]objectAtIndex:i]objectForKey:@"specName"],  [[[severDataDict.dataDict objectForKey:@"specList"]objectAtIndex:i]objectForKey:@"specInv"],formattedNumberString];
                            specName.textColor=zhonghuiColor;
                            specName.font=[UIFont systemFontOfSize:15];
                            [guigeview addSubview:specName];
                            UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(15,45-0.35, ScreenWidth-30, 0.5)];
                            _xianview.image=[UIImage imageNamed:@"hengxian"];
                            [guigeview addSubview:_xianview];
                    
                            [myscrollView addSubview:guigeview];
                        }
                        
                        
                        if (arrr.count>0) {
                            
                            for (int i = 0,j = 0; i < arrr.count; i++) {
                                if (i % 4 == 0) {
                                    j++;
                                }
                                
                                clothView = [[ProductView alloc]initWithFrame:CGRectMake(12.5+(ScreenWidth/4-5)*(i%4), guigeview.bottom+20-50+(50*j), ScreenWidth/4-15, 20)];
                                
                                clothView.buttonView.titleLabel.textAlignment=NSTextAlignmentCenter;
                                clothView.buttonView.titleLabel.font=[UIFont systemFontOfSize:thirteenfotORtwelvefot];
                                [clothView.buttonView setTitle: [[arrr objectAtIndex:i] objectForKey:@"content"] forState:UIControlStateNormal];
                                clothView.buttonView.backgroundColor=[UIColor colorWithRed:255/255.0 green:255/255.0 blue:234/255.0 alpha:1];
                                [clothView.buttonView setTitleColor:huangtitleColor forState:0];
                                [clothView.buttonView.layer setCornerRadius:13.0];
                                [clothView.buttonView.layer setBorderWidth:0.43];
                                [clothView.buttonView.layer setMasksToBounds:YES];
                                CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
                                CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){209/255.0,170/255.0, 56/255.0, 1.0   });
                                [clothView.buttonView.layer setBorderColor:colorref2];//边框颜色
                                //                [clothView.buttonView addTarget:self action:@selector(ItemCodebut:) forControlEvents:UIControlEventTouchUpInside];
                                [myscrollView addSubview:clothView];
                                
                                
                                
                            }
                            
                       
                        }else {
                            
                            NSMutableArray *array1 = [[NSMutableArray alloc] initWithObjects:
                                                      @"无评论",nil];
                            for (int i = 0,j = 0; i < array1.count; i++) {
                                if (i % 4 == 0) {
                                    j++;
                                }
                                
                                clothView = [[ProductView alloc]initWithFrame:CGRectMake(12.5+(ScreenWidth/4-5)*(i%4), guigeview.bottom+20-50+(50*j), ScreenWidth/4-15, 20)];
                                
                                clothView.buttonView.titleLabel.textAlignment=NSTextAlignmentCenter;
                                clothView.buttonView.titleLabel.font=[UIFont systemFontOfSize:thirteenfotORtwelvefot];
                                [clothView.buttonView setTitle: [array1 objectAtIndex:i]  forState:UIControlStateNormal];
                                clothView.buttonView.backgroundColor=[UIColor colorWithRed:255/255.0 green:255/255.0 blue:234/255.0 alpha:1];
                                [clothView.buttonView setTitleColor:huangtitleColor forState:0];
                                [clothView.buttonView.layer setCornerRadius:13.0];
                                [clothView.buttonView.layer setBorderWidth:0.43];
                                [clothView.buttonView.layer setMasksToBounds:YES];
                                CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
                                CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){209/255.0,170/255.0, 56/255.0, 1.0   });
                                [clothView.buttonView.layer setBorderColor:colorref2];//边框
                                [myscrollView addSubview:clothView];}
                        }
                        
                    }else{
                        
                        
                        
//                        NSString *s2 =[NSString stringWithFormat:@"库存 %@",[severDataDict.dataDict objectForKey:@"invQty"]];
//                        UIFont *font2 = [UIFont systemFontOfSize:contenfot];
//                        CGSize size2 = CGSizeMake(ScreenWidth-60, 2000);
//                        CGSize labelsize2 = [s2 sizeWithFont:font2 constrainedToSize:size2 lineBreakMode:NSLineBreakByCharWrapping];
//                        
//                        
//                        
//                        UILabel*kucun=[[UILabel alloc]initWithFrame:CGRectMake(15, view1.bottom-5, labelsize2.width, 45)];
//                        kucun.text=[NSString stringWithFormat:@"库存 %@",[severDataDict.dataDict objectForKey:@"invQty"]];
//                        kucun.font=[UIFont systemFontOfSize:14];
//                        kucun.textColor=zhonghuiColor;
//                        
//                        [myscrollView addSubview:kucun];
                        
                        
                        NSString*GoldPrice=[NSString stringWithFormat:@"%@",  [severDataDict.dataDict objectForKey:@"salePrice"]];
                        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                        [numberFormatter setPositiveFormat:@"###,##0.00;"];
                        NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
                        
                        UILabel*specPrice=[[UILabel alloc]initWithFrame:CGRectMake(20, view1.bottom-5, 200, 45)];
                        specPrice.text=[NSString stringWithFormat:@"¥ %@",formattedNumberString];
                        specPrice.font=[UIFont systemFontOfSize:18];
                        specPrice.textColor=hongsecolor;
                        
                        [myscrollView addSubview:specPrice];
                        UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(15,view1.bottom+45-0.35, ScreenWidth-30, 0.5)];
                        _xianview.image=[UIImage imageNamed:@"hengxian"];
                        [myscrollView addSubview:_xianview];
                        
                        if (arrr.count>0) {
                            
                            for (int i = 0,j = 0; i < arrr.count; i++) {
                                if (i % 4 == 0) {
                                    j++;
                                }
                                
                                clothView = [[ProductView alloc]initWithFrame:CGRectMake(12.5+(ScreenWidth/4-5)*(i%4), specPrice.bottom+20-50+(50*j), ScreenWidth/4-15, 20)];
                                
                                clothView.buttonView.titleLabel.textAlignment=NSTextAlignmentCenter;
                                clothView.buttonView.titleLabel.font=[UIFont systemFontOfSize:thirteenfotORtwelvefot];
                                [clothView.buttonView setTitle: [[arrr objectAtIndex:i] objectForKey:@"content"] forState:UIControlStateNormal];
                                clothView.buttonView.backgroundColor=[UIColor colorWithRed:255/255.0 green:255/255.0 blue:234/255.0 alpha:1];
                                [clothView.buttonView setTitleColor:huangtitleColor forState:0];
                                [clothView.buttonView.layer setCornerRadius:13.0];
                                [clothView.buttonView.layer setBorderWidth:0.43];
                                [clothView.buttonView.layer setMasksToBounds:YES];
                                CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
                                CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){209/255.0,170/255.0, 56/255.0, 1.0   });
                                [clothView.buttonView.layer setBorderColor:colorref2];//边框颜色
                                //                [clothView.buttonView addTarget:self action:@selector(ItemCodebut:) forControlEvents:UIControlEventTouchUpInside];
                                [myscrollView addSubview:clothView];
                                
                                
                                
                            }
                            
                            
                        }else {
                            NSMutableArray *array1 = [[NSMutableArray alloc] initWithObjects:
                                                      @"无评论",nil];
                            for (int i = 0,j = 0; i < array1.count; i++) {
                                if (i % 4 == 0) {
                                    j++;
                                }
                                
                                clothView = [[ProductView alloc]initWithFrame:CGRectMake(12.5+(ScreenWidth/4-5)*(i%4), specPrice.bottom+20-50+(50*j), ScreenWidth/4-15, 20)];
                                
                                clothView.buttonView.titleLabel.textAlignment=NSTextAlignmentCenter;
                                clothView.buttonView.titleLabel.font=[UIFont systemFontOfSize:thirteenfotORtwelvefot];
                                [clothView.buttonView setTitle: [array1 objectAtIndex:i]  forState:UIControlStateNormal];
                                clothView.buttonView.backgroundColor=[UIColor colorWithRed:255/255.0 green:255/255.0 blue:234/255.0 alpha:1];
                                [clothView.buttonView setTitleColor:huangtitleColor forState:0];
                                [clothView.buttonView.layer setCornerRadius:13.0];
                                [clothView.buttonView.layer setBorderWidth:0.43];
                                [clothView.buttonView.layer setMasksToBounds:YES];
                                CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
                                CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){209/255.0,170/255.0, 56/255.0, 1.0   });
                                [clothView.buttonView.layer setBorderColor:colorref2];//边框
                                [myscrollView addSubview:clothView];}
                            
                            
                        }
                        
                        
                    }
                    
                    
                    
                    UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(15, clothView.bottom+20, ScreenWidth-30, 0.40)];
                    line.backgroundColor=LineColor;
                    [myscrollView addSubview:line];
                    
                    
                    UILabel*xiangqing=[[UILabel alloc]initWithFrame:CGRectMake(15, line.bottom+15, 100, 16)];
                    xiangqing.text=@"详情描述";
                    xiangqing.textColor=[UIColor blackColor];
                    xiangqing.font=[UIFont systemFontOfSize:15];
                    [myscrollView addSubview:xiangqing];
                    
                    
                    NSString *s12 = [NSString stringWithFormat:@"%@", [severDataDict.dataDict objectForKey:@"details"]];
                    UIFont *font12 = [UIFont systemFontOfSize:15];
                    CGSize size12 = CGSizeMake(ScreenWidth-30, 2000);
                    CGSize labelsize12 = [s12 sizeWithFont:font12 constrainedToSize:size12 lineBreakMode:NSLineBreakByCharWrapping];
                    
                    
                    
                    UILabel*details2=[[UILabel alloc]initWithFrame:CGRectMake(15, xiangqing.bottom+20, ScreenWidth-30, labelsize12.height)];
                    details2.text=[NSString stringWithFormat:@"%@", [severDataDict.dataDict objectForKey:@"details"]];
                    details2.textColor=shenhuicolor;
                    details2.numberOfLines=0;
                    details2.font=[UIFont systemFontOfSize:15];
                    [myscrollView addSubview:details2];
                    
                    
                    [myscrollView setContentSize:CGSizeMake(ScreenWidth, details2.bottom+64)];
                    
                    
//                    bbuyBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight-45, ScreenWidth*130/750, 45)];
//                    bbuyBtn.backgroundColor=[UIColor whiteColor];
//                    bbuyBtn.alpha=0.48;
//                    [bbuyBtn addTarget:self action:@selector(Addcats:) forControlEvents:UIControlEventTouchUpInside];
//                    [self.view addSubview:bbuyBtn];
//                    
//                    UIButton*Btn=[[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight-45, ScreenWidth*130/750, 45)];
//                    Btn.backgroundColor=[UIColor clearColor];
//                    [Btn addTarget:self action:@selector(Addcats:) forControlEvents:UIControlEventTouchUpInside];
//                    [self.view addSubview:Btn];
//                    
//                    UIButton*buyBtn1=[[UIButton alloc]initWithFrame:CGRectMake(10, 5, ScreenWidth*60/750, ScreenWidth*60/750)];
//                    [buyBtn1 addTarget:self action:@selector(Addcats:) forControlEvents:UIControlEventTouchUpInside];
//                    [buyBtn1 setImage:[UIImage imageNamed:@"gouwuchexiangqing"] forState:UIControlStateNormal];
//                    [self.view addSubview:buyBtn1];
//                    CGPoint sent=bbuyBtn.center;
//                    buyBtn1.center=sent;
//                    
//                    
//                    
//                    
//                    
//                    idname1 = [[UIButton alloc] initWithFrame:CGRectMake(80*ScreenWidth/750, 5, 20, 20)];
//                    idname1.backgroundColor=[UIColor colorWithRed:229.00/255.00 green:19/255.00 blue:19/255.00 alpha:1.0];
//                    [idname1 setTitle:[NSString stringWithFormat: @"%@",@""]forState:UIControlStateNormal];
//                    [idname1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//                    idname1 .titleLabel.font=[UIFont systemFontOfSize:14];
//                    idname1.layer.masksToBounds = YES;
//                    idname1.layer.cornerRadius = 10;
//                    idname1.layer.borderColor = [UIColor whiteColor].CGColor;
//                    idname1.layer.borderWidth = 0;
//                    //idname.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
//                    idname1.titleLabel.textAlignment = NSTextAlignmentCenter;
//                    [Btn addSubview:idname1];
//                    [self duosao];
//                    
//                    
//                    UILabel*line1=[[UILabel alloc]initWithFrame:CGRectMake(0, ScreenHeight-45, ScreenWidth, 0.40)];
//                    line1.backgroundColor=LineColor;
//                    [self.view addSubview:line1];
//                    
//                    UIButton*buyBtn11=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*130/750, ScreenHeight-45, ScreenWidth*620/750, 45)];
//                    [buyBtn11 setTitle:@"加入购物车" forState:UIControlStateNormal];
//                    buyBtn11.backgroundColor=luseColor;
//                    [buyBtn11 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//                    
//                    [buyBtn11 addTarget:self action:@selector(addcat:) forControlEvents:UIControlEventTouchUpInside];
//                    [self.view addSubview:buyBtn11];
                    
                    
                }
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            NSLog(@"aaaaaaaa%@",severDataDict.dataDict);
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
    
}

-(NSString *) getImageFromURLs:(NSString *)imageUrl {
    
    
    
    NSString * results;
    
    
    [imageUrlarrays addObject:imageUrl];
    
    
    commdity.imageUrls=imageUrlarrays;
    return results;
    
}

-(UIImage *) getImageFromURL:(NSString *)fileURL {
    
    
    UIImage * result;
    
    
    
    NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]];
    
    result = [UIImage imageWithData:data];
    
    [imagearrays addObject:result];
    NSLog(@"aaaaaaaa%@",imagearrays);
    
    commdity.imageUrlFullarr=imagearrays;
    return result;
    
}

- (void)erweimaImageview:(UIButton*)sender {
    diview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    diview.backgroundColor=[UIColor blackColor];
    diview.alpha=0.68;
    [self.view addSubview:diview];
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
    singleFingerOne.numberOfTouchesRequired = 1; //手指数
    singleFingerOne.numberOfTapsRequired = 1; //tap次数
    singleFingerOne.delegate = self;
    [diview addGestureRecognizer:singleFingerOne];
    erweima=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth/2,  ScreenWidth/2)];
    erweima.center=diview.center;
    
    erweima.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:erweima];
    
    erweima1=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth/3*1.5,  ScreenWidth/3*1.5)];
    erweima1.center=diview.center;
    
    [erweima1 setImage:[QRCodeGenerator qrImageForString:itemCode imageSize:erweima1.bounds.size.width] forState:UIControlStateNormal];
    [self.view addSubview:erweima1];
}
- (void)addcat:(UIButton*)sender {
    
    specIdarr=[[NSMutableArray alloc]init] ;
    guigetitle=[[NSMutableArray alloc]init] ;
    specInvarr=[[NSMutableArray alloc]init] ;
    price=[[NSMutableArray alloc]init] ;
    
    
    
    
    diview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    diview.backgroundColor=[UIColor blackColor];
    diview.alpha=0.68;
    [self.view addSubview:diview];
    
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
    singleFingerOne.numberOfTouchesRequired = 1; //手指数
    singleFingerOne.numberOfTapsRequired = 1; //tap次数
    singleFingerOne.delegate = self;
    [diview addGestureRecognizer:singleFingerOne];
    
    
    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,200, ScreenWidth, ScreenHeight)];
    
    
    scrollView.backgroundColor=[UIColor whiteColor];
    scrollView.delegate = self;
    scrollView.userInteractionEnabled = YES;
    scrollView.scrollEnabled = YES;
    scrollView.showsVerticalScrollIndicator = FALSE;
    scrollView.showsHorizontalScrollIndicator = FALSE;
    [self.view addSubview:scrollView];
    
    
    
    
    if ([[dataDicts valueForKey:@"imageList"]count]>0) {
        
        
        
        imageview=[[UIImageView alloc]initWithFrame:CGRectMake(15, 20, 85, 85)];
        [imageview setImageWithURL:[NSURL URLWithString:[[[dataDicts valueForKey:@"imageList"] objectAtIndex:0]objectForKey:@"imageUrlFull"]] placeholderImage:nil];
        [imageview.layer setCornerRadius:6.0];
        [imageview.layer setBorderWidth:0.3];
        [imageview.layer setMasksToBounds:YES];
        CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
        CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){ 0, 0, 0, 0.3 });
        [imageview.layer setBorderColor:colorref2];//边框颜色
        [scrollView addSubview:imageview];
    }else{
        imageview=[[UIImageView alloc]initWithFrame:CGRectMake(15, 20, 85, 85)];
        [imageview setImageWithURL:[NSURL URLWithString:@""] placeholderImage:nil];
        [scrollView addSubview:imageview];
    }
    
    UILabel* title=[[UILabel alloc]initWithFrame:CGRectMake(imageview.right+10, 20, ScreenWidth-100, 40)];
    title.text=[NSString stringWithFormat:@"%@",[dataDicts valueForKey:@"itemName"]];
    title.numberOfLines=0;
    title.textColor=[UIColor blackColor];
    title.font=[UIFont systemFontOfSize:15];
    [scrollView addSubview:title];
    
    
    UILabel* fuhao=[[UILabel alloc]initWithFrame:CGRectMake(imageview.right+10, 80, 16, 15)];
    fuhao.text=@"¥";
    fuhao.textColor=[UIColor grayColor];
    fuhao.font=[UIFont systemFontOfSize:14];
    [scrollView addSubview:fuhao];
    
    
    
    
    if ([[dataDicts objectForKey:@"specList"]count]>0) {
        
        NSString*GoldPrice=[NSString stringWithFormat:@"%@",  [dataDicts valueForKey:@"minPrice"]];
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setPositiveFormat:@"###,##0.00;"];
        NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
        
        NSString*GoldPrice1=[NSString stringWithFormat:@"%@",[dataDicts valueForKey:@"maxPrice"]];
        NSNumberFormatter *numberFormatter1 = [[NSNumberFormatter alloc] init];
        [numberFormatter1 setPositiveFormat:@"###,##0.00;"];
        NSString *formattedNumberString1 = [numberFormatter1 stringFromNumber:[NSNumber numberWithDouble:GoldPrice1.floatValue]];
        
        
        UILabel* specPrice=[[UILabel alloc]initWithFrame:CGRectMake(fuhao.right+3, 75, ScreenWidth-100, 18)];
        specPrice.text=[NSString stringWithFormat:@"%@-%@", formattedNumberString,formattedNumberString1];
        specPrice.textColor=[UIColor blackColor];
        specPrice.font=[UIFont systemFontOfSize:18];
        [scrollView addSubview:specPrice];
        
    }else{
        
        NSString*GoldPrice=[NSString stringWithFormat:@"%@",  [dataDicts valueForKey:@"salePrice"]];
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setPositiveFormat:@"###,##0.00;"];
        NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
        
        UILabel* specPrice=[[UILabel alloc]initWithFrame:CGRectMake(fuhao.right+10, 75, ScreenWidth-100, 18)];
        specPrice.text=[NSString stringWithFormat:@"%@", formattedNumberString];
        specPrice.textColor=[UIColor blackColor];
        specPrice.font=[UIFont systemFontOfSize:18];
        [scrollView addSubview:specPrice];
        
        
    }
    
    
    UILabel* xiaoliang=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-150, 80, 130, 14)];
    xiaoliang.text=[NSString stringWithFormat:@"库存  %@",  [dataDicts valueForKey:@"invQty"]];
    xiaoliang.textColor=[UIColor blackColor];
    xiaoliang.font=[UIFont systemFontOfSize:15];
    xiaoliang.textAlignment=NSTextAlignmentRight;
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"库存  %@",  [dataDicts valueForKey:@"invQty"]]];
    
    [AttributedStr addAttribute:NSFontAttributeName
     
                          value:[UIFont systemFontOfSize:15.0]
     
                          range:NSMakeRange(0, 2)];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:zhonghuiColor
     
                          range:NSMakeRange(0, 2)];
    
    
    xiaoliang.attributedText = AttributedStr;
    
    
    
    [scrollView addSubview:xiaoliang];
    
    UILabel*line1=[[UILabel alloc]initWithFrame:CGRectMake(15,imageview.bottom+20, ScreenWidth-30, 0.45)];
    line1.backgroundColor=LineColor;
    [scrollView addSubview:line1];
    
    UILabel* guige=[[UILabel alloc]initWithFrame:CGRectMake(15, line1.bottom+0, 100, 45)];
    guige.text=[NSString stringWithFormat:@"%@",  @"规格选择"];
    guige.textColor=[UIColor blackColor];
    guige.font=[UIFont systemFontOfSize:15];
    [scrollView addSubview:guige];
    
    
    
    
    
    
    
    NSInteger number ;
    number=[[dataDicts objectForKey:@"specList"]count];
    arrays=[dataDicts objectForKey:@"specList"];
    
    if (number>0) {
        
        table_list = [[UITableView alloc]initWithFrame:CGRectMake(0, guige.bottom, ScreenWidth, 100) style:UITableViewStylePlain];
        table_list.delegate = self;
        table_list.dataSource = self;
        table_list.separatorStyle=UITableViewCellSeparatorStyleNone;
        [scrollView addSubview:table_list];
        
        
        
        for (NSDictionary* dicc in arrays )
        {
            
            [guigetitle addObject:[dicc valueForKey:@"specName"]];
            [price addObject:[dicc valueForKey:@"specPrice"]];
            [specIdarr addObject:[dicc valueForKey:@"specId"]];
            
            
            [specInvarr addObject:[dicc valueForKey:@"specInv"]];
            
        }
        
        
        
        
        [table_list reloadData];
        
        
        
        
        
        
        
        
        UILabel* shuliang=[[UILabel alloc]initWithFrame:CGRectMake(15, table_list.bottom+25, 100, 15)];
        shuliang.text=[NSString stringWithFormat:@"%@",  @"购买数量"];
        shuliang.textColor=[UIColor blackColor];
        shuliang.font=[UIFont systemFontOfSize:15];
        [scrollView addSubview:shuliang];
        
        UIImageView*shuimageview=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-140, table_list.bottom+20, 120, 30)];
        shuimageview .image=[UIImage imageNamed:@"tianjias"];
        [scrollView addSubview:shuimageview];
        
        
        shu=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 120, 30)];
        shu.text=[NSString stringWithFormat:@"%@",  @"1"];
        shu.textColor=[UIColor blackColor];
        shu.textAlignment=NSTextAlignmentCenter;
        shu.center=shuimageview.center;
        shu.font=[UIFont systemFontOfSize:15];
        [scrollView addSubview:shu];
        
        UIButton*jian=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-140, table_list.bottom+20, 30, 30)];
        
        [jian addTarget:self action:@selector(jian:) forControlEvents:UIControlEventTouchUpInside];
        [scrollView addSubview:jian];
        
        UIButton*jia=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-50, table_list.bottom+20, 30, 30)];
        [jia addTarget:self action:@selector(jia:) forControlEvents:UIControlEventTouchUpInside];
        [scrollView addSubview:jia];
        
        
        
        
        
    }else{
        
        
        
        
        
        
        
        
        UILabel* shuliang=[[UILabel alloc]initWithFrame:CGRectMake(15, guige.bottom+25, 100, 15)];
        shuliang.text=[NSString stringWithFormat:@"%@",  @"购买数量"];
        shuliang.textColor=[UIColor blackColor];
        shuliang.font=[UIFont systemFontOfSize:15];
        [scrollView addSubview:shuliang];
        
        UIImageView*shuimageview=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-140, guige.bottom+20, 120, 30)];
        shuimageview .image=[UIImage imageNamed:@"tianjias"];
        [scrollView addSubview:shuimageview];
        
        shu=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 120, 30)];
        shu.text=[NSString stringWithFormat:@"%@",  @"1"];
        shu.textColor=[UIColor blackColor];
        shu.center=shuimageview.center;
        shu.textAlignment=NSTextAlignmentCenter;
        shu.font=[UIFont systemFontOfSize:15];
        [scrollView addSubview:shu];
        
        UIButton*jian=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-140, guige.bottom+20, 30, 30)];
        
        [jian addTarget:self action:@selector(jian:) forControlEvents:UIControlEventTouchUpInside];
        [scrollView addSubview:jian];
        
        UIButton*jia=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-50,guige.bottom+20, 30, 30)];
        [jia addTarget:self action:@selector(jia:) forControlEvents:UIControlEventTouchUpInside];
        [scrollView addSubview:jia];
        
        
    }
    
    
    
    
    
    
    
    
    
    
    chaimageview=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-50, 200-15, 30, 30)];
    chaimageview .image=[UIImage imageNamed:@"chas"];
    [self.view addSubview:chaimageview];
    tureBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight-45, ScreenWidth, 45)];
    [tureBtn setTitle:@"确认" forState:UIControlStateNormal];
    tureBtn.backgroundColor=luseColor;
    [tureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [tureBtn addTarget:self action:@selector(tureBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:tureBtn];
    
    
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [guigetitle count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    shouyinCell* cell = (shouyinCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"shouyinCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    UIButton*jiantou = [[UIButton alloc]init];
    jiantou.frame = CGRectMake(0,0, 8, 13);
    [jiantou setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    
    //    cell.accessoryView = jiantou;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.saveAccount=YES;
    
    
    cell.title.text =[NSString stringWithFormat:@"%@ 库存%@",[guigetitle objectAtIndex:indexPath.row],[specInvarr objectAtIndex:indexPath.row]];
    cell.title.font=[UIFont systemFontOfSize:15];
    cell.title.textColor=zhonghuiColor;
    
    
    NSString*GoldPrice=[NSString stringWithFormat:@"%@", [price objectAtIndex:indexPath.row]];
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0;"];
    NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
    
    
    [cell.xuanzeBtn setTitle:[NSString stringWithFormat:@"¥ %@",formattedNumberString] forState:UIControlStateNormal];
    
    cell.xuanzeBtn.tag=indexPath.row;
    
    [cell.xuanzeBtn setTitleColor:hongsecolor forState:UIControlStateNormal];
    cell.xuanzeBtn.frame=CGRectMake(ScreenWidth-300, 0, 280, 45) ;
    cell.xuanzeBtn.titleLabel.textAlignment=NSTextAlignmentRight;
    
    if  ([specId isEqualToString:[specIdarr objectAtIndex:indexPath.row]]){
        
        
        cell.xuanzeimage.image=[UIImage imageNamed:@"gous"];
        
        
    }
    
    
    //    if (guigetitle.count !=indexPath.row+1) {
    //
    //    }
    //
    //    if (indexPath.row==0) {
    //        UILabel *lineLabel31=[[UILabel alloc] initWithFrame:CGRectMake(15, 0, ScreenWidth-30, 0.35)];
    //        lineLabel31.backgroundColor=qianhuicolor;
    //        [cell.contentView addSubview:lineLabel31];
    //
    //    }
    
    
    if (guigetitle.count !=indexPath.row+1) {
        UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(15,44-0.35, ScreenWidth-30, 0.5)];
        _xianview.image=[UIImage imageNamed:@"hengxian"];
        [cell.contentView addSubview:_xianview];
        
        
    }
    
    if (guigetitle.count ==indexPath.row+1) {
        UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(15,44-0.35, ScreenWidth-30, 0.5)];
        _xianview.image=[UIImage imageNamed:@"hengxian"];
        [cell.contentView addSubview:_xianview];
        
        
    }
    
    
    return cell;
    
    
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return  44;
}


#pragma mark - Table view delegate



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
    
    specId=specIdarr[indexPath.row];
    
    for (int i=0;  i<specIdarr.count; i++) {
        NSIndexPath *indexPath1 =[NSIndexPath indexPathForRow:i inSection:0 ];
        UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath1];
        shouyinCell *sharecell=(shouyinCell *)cell;
        
        sharecell.xuanzeimage.image=[UIImage imageNamed:@"quans"];
    }
    
    UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
    shouyinCell *sharecell=(shouyinCell *)cell;
    
    sharecell.xuanzeimage.image=[UIImage imageNamed:@"gous"];
    
    
    
    
    
    
}





-(void)jia:(UIButton*)sender
{
    
    if (specList.count>0) {
        if (specId.length>0) {
            
            
            int d;
            d=shu.text.intValue;
            d++;
            shu.text=[NSString stringWithFormat:@"%d",  d];
        }else{
            
            
            [self showAlertMessage:@"请选择规格！"];
        }
    }else{
        
        int d;
        d=shu.text.intValue;
        d++;
        shu.text=[NSString stringWithFormat:@"%d",  d];
    }
    
    
    
}
-(void)jian:(UIButton*)sender
{
    if (specList.count>0) {
        if (specId.length>0) {
            
            
            int d;
            d=shu.text.intValue;
            
            if (d>=1) {
                d--;
                shu.text=[NSString stringWithFormat:@"%d",  d];
                
            }
            
        }else{
            
            
            [self showAlertMessage:@"请选择规格！"];
        }
    }else{
        
        int d;
        d=shu.text.intValue;
        
        if (d>=1) {
            d--;
            shu.text=[NSString stringWithFormat:@"%d",  d];
            
        }
    }
    
    
    
}
-(void)xuanze:(UIButton*)sender
{
    
    
    specId =sender.titleLabel.text;
    [sender setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
    
    for (int i=0;  i<arrays.count; i++) {
        
        [sender setImage:[UIImage imageNamed:@"gous"] forState:UIControlStateNormal];
        
    }
    
    
}

-(void)Addcats:(UIButton*)sender
{
    ShopcatListViewController* Login=[[ShopcatListViewController alloc]init];
    
    [self.navigationController pushViewController:Login animated:YES];
    
}
//加购物车
-(void)tureBtn:(UIButton*)sender
{
    
    
    
    if (specList.count>0) {
        if (specId.length>0) {
            
            [self queren];
            
        }else{
            
            
            [self showAlertMessage:@"请选择规格！"];
        }
    }else{
        
        [self queren];
    }
    
}
-(void)queren{
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    
    [param setValue:commdity.itemId forKey:@"itemId"];
    
    if (specList.count>0) {
        [param setValue:specId forKey:@"specId"];
        
    }else{
        
        [param setValue:@"" forKey:@"specId"];
    }
    
    [param setValue:shu.text forKey:@"quantity"];
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    
    NSLog(@"%@",param);
    [HttpRequest requestData:@"Business/ShopCart/Add" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                //                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                //
                //                [Global showTextHudSub:requestResultStr view:self.view];
                
                [self duosao];//购物车数量
                
                [tureBtn removeFromSuperview];
                [diview removeFromSuperview];
                [scrollView removeFromSuperview];
                [chaimageview removeFromSuperview];
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            NSLog(@"aaaaaaaa%@",severDataDict.dataDict);
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
    
    
}
-(void)duosao
{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    
    
    
    NSLog(@"====%@",param);
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    
    
    [HttpRequest requestData:@"/Business/ShopCart/Quantity" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            //            NSLog(@"====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                [idname1 setTitle:[NSString stringWithFormat: @"%@",[severDataDict.dataDict objectForKey:@"totalQty"]]forState:UIControlStateNormal];
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                
                
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    
                    //                   NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //                  [Global showTextHud:requestResultStr view:self.view];
                    
                    
                    TheLoginViewController * second =
                    [[TheLoginViewController alloc]
                     initWithNibName:@"TheLoginViewController"
                     bundle:nil];
                    //        second.textt =self.text.text;
                    //        //    second.label.text = @"正向";
                    [self presentViewController:second animated:YES completion:nil];
                    
                }
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
}
- (UIViewController *)appRootViewController
{
    UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
    UIViewController *topVC = appRootVC;
    while (topVC.presentedViewController) {
        topVC = topVC.presentedViewController;
    }
    return topVC;
}

- (void)tapAction {
    UIScrollView *scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    scroll.backgroundColor = [UIColor blackColor];
    [[self appRootViewController].view addSubview:scroll];
    
    UIImageView *imagev = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth,ScreenWidth*image.size.height/image.size.width)];
    imagev.image = image;
    if (imagev.frame.size.height < ScreenHeight) {
        imagev.center = scroll.center;
    }
    
    [scroll addSubview:imagev];
    scroll.contentSize = CGSizeMake(ScreenWidth, imagev.frame.size.height);
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction2)];
    [scroll addGestureRecognizer:tap];
    scroll.tag = 100;
}

- (void)tapAction2 {
    UIScrollView *scroll = (UIScrollView *)[[self appRootViewController].view viewWithTag:100];
    [scroll removeFromSuperview];
}


- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}


@end
